<?php

/*
 * Yanis Framework, Yet ANother Internet Service for web and mobile technologists
 * @copyright Copyright (C) 2011 ch@rlesen. All rights reserved.
 * @license GNU/GPL
 * @author Charles EDOU NZE <charles at charlesen.fr>
 */

/**
 * Class Framework
 */
session_start();
require YANIS_PATH . 'libraries/yanis/registry/registry.php';

class Framework {

    /**
     * Run the framework
     */
    public static function run() {
        
    }

    /**
     * Framework exit() method
     */
    public static function zyva() {
        
    }

    /**
     * @param String $filePath the file path
     */
    public static function import($filePath) {
        //TODO: Register the classname in the Registry. To be implemented !
        /**
          static $paths;
          if (!isset($paths)) {
          $paths = array();
          }

          $parts = explode('.', $filePath);

          $classname = array_pop($parts); //Return the last segment (ex: a.b.c, returns 'c')
          switch ($classname) {
          case 'helper' :
          $classname = ucfirst(array_pop($parts)) . ucfirst($classname);
          break;

          default :
          $classname = ucfirst($classname);
          break;
          }
         */
        $base = YANIS_PATH . DS . 'librairies' . DS . 'yanis';
        $path = str_replace('.', DS, $filePath);

        include_once($base . DS . $path . '.php');
    }

    public static function loadModule($moduleName) {
        //TODO:Implement the method for this week
    }

}

/**
 * Intelligent file importer
 *
 * @access public
 * @param String $path dot syntax path
 */
function yimport($path) {
    Framework::import($path);
}

/**
 * Class Factory
 */
class Factory {

    //TODO : Implementer le Factory -~- $database =& YFactory::getDBO();
    //Récupérer tous les core objets (template, db, user, session, doc,...)

    //public static $document = null;
    //public static $database = null;

    /**
     * @var Object The Registry object 
     */
    private $registry;

    public function __construct(Registry $registry) {
        $this->registry = $registry;
    }

    /**
     * Get an user object. Returns a reference to the global User object.
     *
     * @param int $id
     * @access public
     * @return object User 
     */
    static function &getUser($id = null) {
        //$user =& JUser::getInstance($id);
        //$user =& JFactory::getUser(99);
        //echo "<p>Your name is {$user->name}, your email is {$user->email};
        //yimport('yanis.user.user');

        return $this->registry->getObject('user');
    }

    /**
     * @return Object Database 
     */
    static function &getDB($dbType = 'mysqldb') {
        return $this->registry->getObject($dbType);
    }

    /**
     * @return Object Document 
     */
    static function &getDocument($docType = 'page') {
        return $this->registry->getObject($docType);
    }

}

?>
